package bean;

public class JavaClass {
    public volatile Integer a = 0;
    Integer obj = new Integer(0);

    public int add(int c){
        c = 1;
        a = c;
        a = c + a;
        c++;
        return c;
//        System.out.println("a:" + a + "   c:" + c);
    }

    public void start(){
        VolatileThread thread1 = new VolatileThread();
        VolatileThread thread2 = new VolatileThread();
        thread1.start();
        thread2.start();
    }



    public static void main(String[] args) {

        JavaClass javaClass = new JavaClass();
        javaClass.start();

    }


    public class VolatileThread extends Thread{
        @Override
        public void run() {
            super.run();

            synchronized (obj){
                for (int i = 0; i < 100000; i++){

                    a++;
                    System.out.println("ThreadName:" + Thread.currentThread().getName() + "  value:" + a);
                }

            }

        }
    }
}
